package sn.gandal.mobile.kalpet.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.util.Log;

public class PropertiesUtils {
	
	public static String getString(Context cx, String key){
		Resources resources = cx.getResources();
		AssetManager assetManager = resources.getAssets();
		String message="";
		String returnValue=null;
		try {
		    InputStream rawResource = assetManager.open("env.properties");
		    Properties properties = new Properties();
		    properties.load(rawResource);		   
		    returnValue =properties.getProperty(key);
		    
		} catch (NotFoundException e) {
		 //Log.ERROR("Did not find raw resource: "+e);
		} catch (IOException e) {
			//message="Failed to open microlog property file";
		}
	return returnValue;	
	}
	
	public static Boolean getBoolean(Context cx, String key){
		Resources resources = cx.getResources();
		AssetManager assetManager = resources.getAssets();
		Boolean returnValue=null;
		try {
		    InputStream rawResource = assetManager.open("env.properties");
		    Properties properties = new Properties();
		    properties.load(rawResource);		   
		    returnValue =Boolean.valueOf(properties.getProperty(key).trim());
		    
		} catch (NotFoundException e) {
		 //Log.ERROR("Did not find raw resource: "+e);
		} catch (IOException e) {
			//message="Failed to open microlog property file";
		}
	return returnValue;	
	}
	
	public static Integer getInteger(Context cx, String key){
		Resources resources = cx.getResources();
		AssetManager assetManager = resources.getAssets();
		Integer returnValue=null;
		try {
		    InputStream rawResource = assetManager.open("env.properties");
		    Properties properties = new Properties();
		    properties.load(rawResource);		   
		    returnValue =Integer.decode(properties.getProperty(key));
		    
		} catch (NotFoundException e) {
		 //Log.ERROR("Did not find raw resource: "+e);
		} catch (IOException e) {
			//message="Failed to open microlog property file";
		}
	return returnValue;	
	}

}
